let {list}=require('./mock')
let users=[{
    username:'aindmi',
    password:'123',
    token:'aindmi',
    id:'1'
},{
    username:'123',
    password:'321',
    token:'user',
    id:'2'
},]
module.exports=app=>{
    app.get('/api/list',(req,res)=>{
        res.send({
            list
        })
    })
    app.get('/api/dele',(req,res)=>{
        const {selectedRowKeys}=req.query
        list=list.filter(v=>!selectedRowKeys.includes(v.key))
        res.send({
            code:200
        })
    })
    app.get('/api/item',(req,res)=>{
        const {key}=req.query
        const s=list.find(v=>v.key===key)
        res.send({
            item:s
        })
    })
    app.get('/api/login',(req,res)=>{
        const {username,password}=req.query
        const s=users.find(v=>v.password===password&&v.username===username)
        if(s){
            res.send({
                code:200,
                token:s.token,
                title:'登录成功！！！'
            })
        }else{
            res.send({
                code:401,
                title:'登录失败！！！'
            })
        }
    })
}